#include "RootWidget.h"

#include "Window.h"

#include "Platform/Window/SystemWindowInterface.h"
#include "Render/Widget/RenderWidgets.h"

RApplication *RRootWidget::GetApplication()
{
    return Application;
}

void RRootWidget::SetApplication(RApplication *InApplication)
{
    Application = InApplication;
}

void RRootWidget::CalculatePresentPositionAndSize()
{
    PresentAbsPosition.X=0;
    PresentAbsPosition.Y=0;

    PresentSize.X=Width.Get();
    PresentSize.Y=Height.Get();

    CalculateChildrenPresentPositionAndSize();
}

TOptional<SRect> RRootWidget::GetPaintArea()
{
    return SRect(0,0,Width.Get(),Height.Get());
}

TOptional<SRect> RRootWidget::GetSubWidgetPaintArea()
{
    return SRect(0,0,Width.Get(),Height.Get());
}


TSharedObjectPtr<RWindow> RRootWidget::GetWindow()
{
    return (TSharedObjectPtr<RWindow>)GetOwner();
}



void RRootWidget::PaintSelf(uint16_t& InZOrder,const SRect& InClipArea)
{
    bool _bFill=Fill.Get();
    if(!_bFill)
    {
        return;
    }

    auto RenderRectWidget=std::make_shared<SRenderRectWidget>();
    RenderRectWidget->Rect=SRect(PresentAbsPosition,PresentSize);
    RenderRectWidget->ClipRect=InClipArea;
    RenderRectWidget->ZOrder=InZOrder;

    RenderRectWidget->bFill=true;
    RenderRectWidget->FillColor=FillColor.Get();
    RenderRectWidget->BorderSize=0;
    RenderRectWidget->Radius=0;
    InZOrder++;

    PaintRenderWidget(
        RenderRectWidget);
}